package com.scsj.supermarket.adapter.homeadapter;

import android.content.Context;
import android.provider.FontRequest;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scsj.supermarket.R;
import com.scsj.supermarket.adapter.IndexGoodsListAdapter;
import com.scsj.supermarket.adapter.IndexLimitRobAdapter;
import com.scsj.supermarket.bean.IndexBean;
import com.scsj.supermarket.bean.IndexGoodsListBean;
import com.scsj.supermarket.bean.IndexMarketBean;
import com.scsj.supermarket.bean.MineBean;
import com.scsj.supermarket.bean.homebean.HomeRecommendBean;
import com.scsj.supermarket.customview.MyDecoration;
import com.scsj.supermarket.customview.MyItemDecoration;
import com.scsj.supermarket.customview.countdownview.CountdownView;
import com.scsj.supermarket.utils.GridSpacingItemDecoration;
import com.scsj.supermarket.utils.SkipUtils;
import com.scsj.supermarket.utils.ToastMiddleUtils;
import com.scsj.supermarket.view.activity.mainmodel.MainActivity;
import com.youth.banner.Banner;
import com.youth.banner.listener.OnBannerListener;
import com.youth.banner.loader.ImageLoader;
import com.youth.banner.transformer.AccordionTransformer;
import com.youth.banner.transformer.BackgroundToForegroundTransformer;
import com.youth.banner.transformer.CubeInTransformer;
import com.youth.banner.transformer.CubeOutTransformer;
import com.youth.banner.transformer.DefaultTransformer;
import com.youth.banner.transformer.DepthPageTransformer;
import com.youth.banner.transformer.FlipHorizontalTransformer;
import com.youth.banner.transformer.FlipVerticalTransformer;
import com.youth.banner.transformer.ForegroundToBackgroundTransformer;
import com.youth.banner.transformer.RotateDownTransformer;
import com.youth.banner.transformer.RotateUpTransformer;
import com.youth.banner.transformer.ScaleInOutTransformer;
import com.youth.banner.transformer.StackTransformer;
import com.youth.banner.transformer.TabletTransformer;
import com.youth.banner.transformer.ZoomInTransformer;
import com.youth.banner.transformer.ZoomOutSlideTransformer;
import com.youth.banner.transformer.ZoomOutTranformer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import es.dmoral.toasty.Toasty;

/**
 * 首页所有内容
 */
public class HomeRecycleViewAdapter extends RecyclerView.Adapter {

    private static CountdownView mCvCountdownView;
    /**
     * 5种类型
     */
    /**
     * 类型1：使用banner实现
     */
    public static final int TOPBANNER = 0;
    /**
     * 类型2：十个功能键--使用recyclerview实现
     */
    public static final int FUNC_BTN = 1;
    /**
     * 类型3：广告栏--使用ImageView实现
     */
    public static final int AD = 2;
    /**
     * 类型4：限时抢购--使用RecyclerView实现
     */
    public static final int FLASHSALE = 3;
    /**
     * 类型5：推荐-使用RecyclerView实现
     */
    public static final int RECOMMEND = 4;
    /**
     * 类型6：附近店铺推荐
     */
    public static final int MARKET = 5;
    /**
     * 当前类型
     */
    public int currentType = TOPBANNER;

    private Context mContext = null;

    private IndexBean indexBeans;
    /**
     * 初始化布局
     */
    private LayoutInflater mLayoutInflater = null;

    public HomeRecycleViewAdapter(Context mContext, IndexBean indexBeans) {
        this.mContext = mContext;
        this.indexBeans = indexBeans;
        //以后用它来初始化布局
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    private LinearLayout mainCommendShops;
    private List<MineBean> funcList = new ArrayList<>();
    private List<IndexGoodsListBean.IndexGoodsList> indexGoodsListBeans;

    /**
     * 相当于getView创建ViewHolder布局
     */
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        if (viewType == TOPBANNER) {
            return new TopBannerViewHolder(mContext, mLayoutInflater.inflate(R.layout.home_banner_layout, null));
        } else if (viewType == FUNC_BTN) {
            return new FuncBtnViewHolder(mContext, mLayoutInflater.inflate(R.layout.home_func_btn_layout, null));
        } else if (viewType == AD) {
            return new ADViewHolder(mContext, mLayoutInflater.inflate(R.layout.home_ad_layout, null));
        } else if (viewType == FLASHSALE) {
            return new FlashSaleViewHolder(mContext, mLayoutInflater.inflate(R.layout.home_flash_sale_layout, null));
        } else if (viewType == RECOMMEND) {
            return new RecommendViewHolder(mContext, mLayoutInflater.inflate(R.layout.home_recommend_layout, null));
        } else if (viewType == MARKET) {
            return new MarketViewHolder(mContext, mLayoutInflater.inflate(R.layout.home_market_layout, null));
        }
        return null;
    }

    /**
     * 相当于getView中的绑定数据模块
     */
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if (getItemViewType(position) == TOPBANNER) {
            TopBannerViewHolder bbnViewHolder = (TopBannerViewHolder) holder;
            ArrayList<String> images = new ArrayList<>();
            ArrayList<String> type = new ArrayList<>();
            int size = indexBeans.getData().get(0).getAppAdvertisingVoList().size();
            for (int i = 0; i < size; i++) {
                images.add(indexBeans.getData().get(0).getAppAdvertisingVoList().get(i).getResourceInfo().getUrlFrameCapture());
                type.add(indexBeans.getData().get(0).getAppAdvertisingVoList().get(i).getAdvertising().getTargetType());
            }
            bbnViewHolder.setData(images, type);
        } else if (getItemViewType(position) == FUNC_BTN) {
            FuncBtnViewHolder todayViewHolder = (FuncBtnViewHolder) holder;
            ArrayList<String> imgUrl = new ArrayList<>();
            ArrayList<String> title = new ArrayList<>();
            int funcSize = indexBeans.getData().get(1).getAppAdvertisingVoList().size();
            for (int i = 0; i < funcSize; i++) {
                imgUrl.add(indexBeans.getData().get(1).getAppAdvertisingVoList().get(i).getResourceInfo().getUrlFrameCapture());
                title.add(indexBeans.getData().get(1).getAppAdvertisingVoList().get(i).getAdvertising().getTitle());
            }
            todayViewHolder.setData(imgUrl, title);
        } else if (getItemViewType(position) == AD) {
            ADViewHolder pinpaiViewHolder = (ADViewHolder) holder;
            ArrayList<String> imgUrl = new ArrayList<>();
            ArrayList<String> type = new ArrayList<>();
            for (int i = 0; i < indexBeans.getData().get(2).getAppAdvertisingVoList().size(); i++) {
                type.add(indexBeans.getData().get(2).getAppAdvertisingVoList().get(i).getAdvertising().getTargetType());
                imgUrl.add(indexBeans.getData().get(2).getAppAdvertisingVoList().get(i).getResourceInfo().getUrlFrameCapture());
            }
            pinpaiViewHolder.setData(imgUrl, type);
        } else if (getItemViewType(position) == FLASHSALE) {
            FlashSaleViewHolder dapeiViewHolder = (FlashSaleViewHolder) holder;
            dapeiViewHolder.setData(indexBeans);
        } else if (getItemViewType(position) == RECOMMEND) {
            RecommendViewHolder recommendViewHolder = (RecommendViewHolder) holder;
            ArrayList<HomeRecommendBean> recommendList = new ArrayList<>();
            int recommendSize = indexBeans.getData().get(5).getAppAdvertisingVoList().size();
            for (int i = 0; i < recommendSize; i++) {
                recommendList.add(new HomeRecommendBean("https://oss.scsj.net.cn/images/users/testtest/ed0964be-179e-4e87-ac8e-b6e270b13091.jpg?imageView2/2/w/720/h/380&e=1530670089&token=lzJVdwCFPYaBjRTG0TsKRw_Eo-YXFx93AhzeX0dY:3Q1M_2RtZnkDB1voF6a3ecl9EtQ=", "商务外环路CBD店有售", indexBeans.getData().get(5).getAppAdvertisingVoList().get(i).getAdvertising().getNote(), "500", "200"));
            }
            recommendViewHolder.setData(recommendList);
        } else if (getItemViewType(position) == MARKET) {
            MarketViewHolder marketViewHolder = (MarketViewHolder) holder;
            marketViewHolder.setData();
        }
    }

    /**
     * 总共有多少个item
     */
    @Override
    public int getItemCount() {
        return 6;
    }

    /**
     * 返回类型
     */
    @Override
    public int getItemViewType(int position) {
        switch (position) {
            case TOPBANNER:
                currentType = TOPBANNER;
                break;
            case FUNC_BTN:
                currentType = FUNC_BTN;
                break;
            case AD:
                currentType = AD;
                break;
            case FLASHSALE:
                currentType = FLASHSALE;
                break;
            case RECOMMEND:
                currentType = RECOMMEND;
                break;
            case MARKET:
                currentType = MARKET;
                break;
        }
        return currentType;
    }

    /**
     * 限时抢购
     */
    public class FlashSaleViewHolder extends RecyclerView.ViewHolder {

        private Context mContext;
        private RecyclerView flash_rv;
        private IndexLimitRobAdapter adapter;
        private LinearLayout home_left_ll, home_right_ll;
        private ImageView time_limited_left1_iv, time_limited_left2_iv, time_limited_right1_iv, time_limited_right2_iv;
        private TextView title_tv, content_tv, price_left_tv1, price_left_tv2, price_right_tv1, price_right_tv2, time_tv, type_tv;

        public FlashSaleViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;

            time_limited_left1_iv = itemView.findViewById(R.id.time_limited_left1_iv);
            time_limited_left2_iv = itemView.findViewById(R.id.time_limited_left2_iv);
            time_limited_right1_iv = itemView.findViewById(R.id.time_limited_right1_iv);
            time_limited_right2_iv = itemView.findViewById(R.id.time_limited_right2_iv);
            title_tv = itemView.findViewById(R.id.title_tv);
            content_tv = itemView.findViewById(R.id.content_tv);
            time_tv = itemView.findViewById(R.id.time_tv);
            price_left_tv1 = itemView.findViewById(R.id.price_left_tv1);
            price_left_tv2 = itemView.findViewById(R.id.price_left_tv2);
            price_right_tv1 = itemView.findViewById(R.id.price_right_tv1);
            price_right_tv2 = itemView.findViewById(R.id.price_right_tv2);
            type_tv = itemView.findViewById(R.id.type_tv);
            home_left_ll = itemView.findViewById(R.id.home_left_ll);
            home_right_ll = itemView.findViewById(R.id.home_right_ll);

            flash_rv = itemView.findViewById(R.id.flash_rv);
            int spanCount = 3; // 3 columns
            int spacing = 60; // 50px
            boolean includeEdge = false;
            flash_rv.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, includeEdge));
            flash_rv.setLayoutManager(new GridLayoutManager(mContext, 3));
            flash_rv.setNestedScrollingEnabled(false);

            mainCommendShops = itemView.findViewById(R.id.hot_shops_layout);
            mCvCountdownView = (CountdownView) itemView.findViewById(R.id.cv_countdownView);
        }

        public void setData(IndexBean indexBeans) {

            int size = indexBeans.getData().get(4).getAppAdvertisingVoList().size();
            ArrayList<HomeRecommendBean> recommendBeans = new ArrayList<>();
            for (int i = 0; i < size; i++) {
                recommendBeans.add(new HomeRecommendBean(indexBeans.getData().get(4).getAppAdvertisingVoList().get(i).getResourceInfo().getUrlFrameCapture(), indexBeans.getData().get(4).getAppAdvertisingVoList().get(i).getAdvertising().getNote(), indexBeans.getData().get(4).getAppAdvertisingVoList().get(i).getAdvertising().getTitle(), "33", "22"));
            }

            title_tv.setText(indexBeans.getData().get(3).getAppAdvertisingVoList().get(1).getAdvertising().getTitle());
            content_tv.setText(indexBeans.getData().get(3).getAppAdvertisingVoList().get(1).getAdvertising().getNote());

            Glide.with(mContext).load(indexBeans.getData().get(3).getAppAdvertisingVoList().get(1).getResourceInfo().getUrlFrameCapture()).into(time_limited_right1_iv);
            Glide.with(mContext).load(indexBeans.getData().get(3).getAppAdvertisingVoList().get(1).getResourceInfo().getUrlFrameCapture()).into(time_limited_right2_iv);

            Glide.with(mContext).load(indexBeans.getData().get(3).getAppAdvertisingVoList().get(0).getResourceInfo().getUrlFrameCapture()).into(time_limited_left1_iv);
            Glide.with(mContext).load(indexBeans.getData().get(3).getAppAdvertisingVoList().get(0).getResourceInfo().getUrlFrameCapture()).into(time_limited_left2_iv);

            home_left_ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SkipUtils.toLimitRob(mContext);
                }
            });
            home_right_ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    SkipUtils.toTenFunc(mContext, 10);
                }
            });

            adapter = new IndexLimitRobAdapter(recommendBeans);
            flash_rv.setAdapter(adapter);
            adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    switch (position) {
                        case 0:
                            SkipUtils.toGoodsDetails(mContext, 2);
                            break;
                        case 1:
                            SkipUtils.toGoodsDetails(mContext, 2);
                            break;
                        case 2:
                            SkipUtils.toGoodsDetails(mContext, 2);
                            break;
                    }
                }
            });

            mCvCountdownView.start(100000);
            new Thread(new Runnable() {
                @Override
                public void run() {
                    mCvCountdownView.updateShow(1);
                }
            }).start();
            CountdownView mCvCountdownView = (CountdownView) itemView.findViewById(R.id.cv_countdownView);
            mCvCountdownView.start(995550); // 毫秒

            // 自己编写倒计时逻辑，然后调用updateShow来更新UI
            for (int time = 0; time < 1000; time++) {
                mCvCountdownView.updateShow(time);
            }
            // View addViewLayout = LayoutInflater.from(this).inflate(R.id.hot_shops_layout,null);
            //添加之前先移除所有字View
            if (mainCommendShops.getChildCount() > 0) {
                mainCommendShops.removeAllViews();
            }
        }
    }

    public static void startCountTime() {
        if (mCvCountdownView != null) {
            mCvCountdownView.start(995550); // 毫秒
            // 自己编写倒计时逻辑，然后调用updateShow来更新UI
            for (int time = 0; time < 1000; time++) {
                mCvCountdownView.updateShow(time);
            }
        }
    }

    /**
     * 推荐商品
     */
    class RecommendViewHolder extends RecyclerView.ViewHolder {

        private final Context mContext;
        private RecyclerView home_recommend_rv;
        private HomeRecommendAdapter homeRecommendAdapter;

        public RecommendViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            home_recommend_rv = itemView.findViewById(R.id.home_recommend_rv);
            int spanCount = 3; // 3 columns
            int spacing = 50; // 50px
            boolean includeEdge = false;
            home_recommend_rv.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, includeEdge));
            home_recommend_rv.setLayoutManager(new GridLayoutManager(mContext, 3));
            home_recommend_rv.setNestedScrollingEnabled(false);
        }

        public void setData(ArrayList<HomeRecommendBean> recommendList) {
            homeRecommendAdapter = new HomeRecommendAdapter(recommendList, 0);
            home_recommend_rv.setAdapter(homeRecommendAdapter);
            homeRecommendAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    switch (position) {
                        case 0:
                            SkipUtils.toGoodsDetails(mContext, 2);
                            break;
                        case 1:
                            SkipUtils.toGoodsDetails(mContext, 2);
                            break;
                        case 2:
                            SkipUtils.toGoodsDetails(mContext, 2);
                            break;
                    }
                }
            });
        }
    }

    /**
     * 十个功能键
     */
    public class FuncBtnViewHolder extends RecyclerView.ViewHolder {

        private final Context mContext;
        private RecyclerView func_btn_rv;
        private Map<String, String> map;

        public FuncBtnViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            func_btn_rv = itemView.findViewById(R.id.func_btn_rv);

            int spanCount = 5; // 3 columns
            int spacing = 50; // 50px
            boolean includeEdge = false;

            func_btn_rv.addItemDecoration(new GridSpacingItemDecoration(spanCount, spacing, includeEdge));
            func_btn_rv.setLayoutManager(new GridLayoutManager(mContext, 5));
            func_btn_rv.setNestedScrollingEnabled(false);
        }

        public void setData(ArrayList<String> imgUrl, ArrayList<String> title) {

            for (int i = 0; i < imgUrl.size(); i++) {
                funcList.add(new MineBean(imgUrl.get(i), title.get(i)));
            }
            HomeFuncAdapter homeFuncAdapter = new HomeFuncAdapter(funcList);
            func_btn_rv.setAdapter(homeFuncAdapter);
            homeFuncAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    switch (position) {
                        case 0:
                            SkipUtils.toTenFunc(mContext, 0);
                            break;
                        case 1:
                            SkipUtils.toTenFunc(mContext, 1);
                            break;
                        case 2:
                            SkipUtils.toTenFunc(mContext, 2);
                            break;
                        case 3:
                            SkipUtils.toTenFunc(mContext, 3);
                            break;
                        case 4:
                            SkipUtils.toTenFunc(mContext, 4);
                            break;
                        case 5:
                            SkipUtils.toTenFunc(mContext, 5);
                            break;
                        case 6:
                            SkipUtils.toTenFunc(mContext, 6);
                            break;
                        case 7:
                            SkipUtils.toTenFunc(mContext, 7);
                            break;
                        case 8:
                            SkipUtils.toTenFunc(mContext, 8);
                            break;
                        case 9:
                            MainActivity mmContext = (MainActivity) FuncBtnViewHolder.this.mContext;
                            mmContext.skipToVP(1);
                            break;
                        default:
                            break;
                    }
                }
            });
        }
    }

    public void setShops(IndexMarketBean indexMarketBean) {

        indexGoodsListBeans = new ArrayList<>();
        int size = indexMarketBean.getData().get(0).getAppAdvertisingVoList().size();
        for (int i = 0; i < size; i++) {
            IndexMarketBean.DataBean.AppAdvertisingVoListBean.AppStoreAdvertisingVoBean appStoreAdvertisingVo = indexMarketBean.getData().get(0).getAppAdvertisingVoList().get(i).getAppStoreAdvertisingVo();
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList(appStoreAdvertisingVo.getResourceLogoInfo().getUrlFrameCapture(), appStoreAdvertisingVo.getStore().getName(), "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
            indexGoodsListBeans.add(new IndexGoodsListBean.IndexGoodsList("hahaahhah", "fdfsf", "已保", "实体店", "商超配送", 2, "月售500单", "18元起送", "领券", "配送18元起"));
        }
    }

    /**
     * 店铺推荐
     */
    class MarketViewHolder extends RecyclerView.ViewHolder {

        private Context mContext;
        private RecyclerView market_rv;
        private IndexGoodsListAdapter adapter;

        public MarketViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            market_rv = itemView.findViewById(R.id.home_market_rv);
            market_rv.setLayoutManager(new LinearLayoutManager(mContext));
            market_rv.setNestedScrollingEnabled(false);
        }

        public void setData() {
            adapter = new IndexGoodsListAdapter(indexGoodsListBeans);
            market_rv.setAdapter(adapter);
            adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    switch (position) {
                        case 0:
                            SkipUtils.toMarketDetail(mContext);
                            break;
                        case 1:
                            SkipUtils.toMarketDetail(mContext);
                            break;
                        case 2:
                            SkipUtils.toMarketDetail(mContext);
                            break;
                    }
                }
            });
        }
    }

    /**
     * 广告栏
     */
    static class ADViewHolder extends RecyclerView.ViewHolder {

        private final Context mContext;
        private Banner banner;

        ADViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            banner = itemView.findViewById(R.id.home_banner2);
        }

        public void setData(ArrayList<String> imgUrl, final ArrayList<String> type) {
            banner.setImages(imgUrl).setImageLoader(new GlideImageLoader()).start();
            banner.setOnBannerListener(new OnBannerListener() {
                @Override
                public void OnBannerClick(int position) {
                    if (type.get(position).equals("shop_goods")) {
                        SkipUtils.toGoodsDetails(mContext, 2);
                    } else if (type.get(position).equals("shop_store")) {
                        SkipUtils.toMarketDetail(mContext);
                    } else {
                        Toasty.info(mContext, "抱歉，没有找到您想要的商品").show();
                    }
                }
            });
        }
    }

    /**
     * 轮播图
     */
    public static class TopBannerViewHolder extends RecyclerView.ViewHolder implements AdapterView.OnItemClickListener, OnBannerListener {

        private final Context mContext;
        private Banner banner;
        List<Class<? extends ViewPager.PageTransformer>> transformers = new ArrayList<>();

        public TopBannerViewHolder(Context mContext, View itemView) {
            super(itemView);
            this.mContext = mContext;
            initTransFormData();
            banner = itemView.findViewById(R.id.home_banner);
        }

        public void setData(final ArrayList<String> images, final ArrayList<String> type) {

            //新版的banner的使用----偷下懒的使用方法
            banner.setImages(images)
                    .setImageLoader(new GlideImageLoader())
                    .setOnBannerListener(this)
                    .start();

            banner.setOnBannerListener(new OnBannerListener() {
                @Override
                public void OnBannerClick(int position) {

                    if (type.get(position).equals("shop_store")) {
                        SkipUtils.toMarketDetail(mContext);
                    } else if (type.get(position).equals("shop_goods")) {
                        SkipUtils.toGoodsDetails(mContext, 2);
                    } else {
                        Toasty.info(mContext, "抱歉，没有找到您想要的商品").show();
                    }

                    switch (position) {
                        case 0:
                            SkipUtils.toMarketDetail(mContext);
                            break;
                        case 1:
                            SkipUtils.toGoodsDetails(mContext, 0);
                            break;
                        case 2:
                            SkipUtils.toGoodsDetails(mContext, 0);
                            break;
                        case 3:
                            SkipUtils.toGoodsDetails(mContext, 0);
                            break;

                    }
                }
            });
        }

        public void initTransFormData() {
            transformers.add(DefaultTransformer.class);
            transformers.add(AccordionTransformer.class);
            transformers.add(BackgroundToForegroundTransformer.class);
            transformers.add(ForegroundToBackgroundTransformer.class);
            transformers.add(CubeInTransformer.class);//兼容问题，慎用
            transformers.add(CubeOutTransformer.class);
            transformers.add(DepthPageTransformer.class);
            transformers.add(FlipHorizontalTransformer.class);
            transformers.add(FlipVerticalTransformer.class);
            transformers.add(RotateDownTransformer.class);
            transformers.add(RotateUpTransformer.class);
            transformers.add(ScaleInOutTransformer.class);
            transformers.add(StackTransformer.class);
            transformers.add(TabletTransformer.class);
            transformers.add(ZoomInTransformer.class);
            transformers.add(ZoomOutTranformer.class);
            transformers.add(ZoomOutSlideTransformer.class);
        }

        @Override
        public void OnBannerClick(int position) {
            Toasty.error(mContext, "你点击了" + position + "位置").show();
        }

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            banner.setBannerAnimation(transformers.get(i));
        }
    }


    /**
     * 图片加载器
     */
    public static class GlideImageLoader extends ImageLoader {
        @Override
        public void displayImage(Context context, Object path, ImageView imageView) {

            imageView.setScaleType(ImageView.ScaleType.FIT_XY);

            //Glide 加载图片简单用法
            Glide.with(context).load(path).into(imageView);
        }
    }
}


